package com.bzframework.pro.authorize.service;

import com.bzframework.pro.authorize.entity.UserEntity;
import org.hswebframework.web.crud.service.GenericReactiveCrudService;
import org.hswebframework.web.exception.NotFoundException;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

/**
 * @Author bingzhong
 * @Date 2024/11/29 10:13
 * @Description
 */
@Service
public class UserService extends GenericReactiveCrudService<UserEntity, String> {
    public Mono<UserEntity> getSafetyUser(String id) {

        return createQuery()
                .where(UserEntity::getId, id)
                .fetchOne()
                .switchIfEmpty(Mono.error(new NotFoundException("用户不存在")))
                .map(userEntity -> {
                    userEntity.setPassword(null);
                    userEntity.setSalt(null);
                    return userEntity;
                });

    }
}
